/*
 * @Author: 0x9DEFA478
 * @Date: 2021-08-14 17:36:05
 * @LastEditTime: 2024-07-16 22:51:29
 * @LastEditors: 0x9DEFA478
 * @Description: 
 * QQ:2652450237
 * ============================================================================================================================================
 * 
 * 
 * 
 *                                                                                               ************      ****************************
 *                                                                                             ************      ****************************  
 *                                                                                           ************      ****************************    
 *                                                                                         ************      ****************************      
 *                                                                                       ************      ************                        
 *                                                                                     ************      ************                          
 *                                                                                   ************      ************                            
 *                                                                                 ************      ************                              
 *                                                                               ************      ************                                
 *                                                                             ************      ************                                  
 *                                                                           ************      ************                                    
 *                                                                         ************      ************                                      
 *                                                                       ************      ************                                        
 *                                                                     ************      ************                                          
 *                                                                   ************      ************                                            
 *                                                                 ************      ************                                              
 *                                                               ************      ************                                                
 *                                                             ************      ************                                                  
 *                                                           ************      ************                                                    
 *                                                         ************      ************                                                      
 *                                                       ************      ************                                                        
 *                                                     ************      ************                                                          
 *                                                   ************      ************                                                            
 *                                                 ************      ************                                                              
 *                                               ************      ************                                                                
 *                                             ************      ************                                                                  
 *                                           ************      ************                                                                    
 *                                         ************      ************                                                                      
 *                                       ************      ************                                                                        
 *                                     ************      ************                                                                          
 *                                   ************      ************                                                                            
 *                                 ************      ************                                                                              
 *                               ************      ************                                                                                
 *                             ************      ************                                                                                  
 *                           ************      ************                                                                                    
 *                         ************      ************                                                                                      
 *       ****************************      ************                                                                                        
 *     ****************************      ************                                                                                          
 *   ****************************      ************                                                                                            
 * ****************************      ************                                                                                              
 * 
 * 
 * 
 * ============================================================================================================================================
 * 
 */
#include "H_FIFO.h"




#define H_FIFO_byte_Type                                          Hbyte




#if   H_FIFO_SizeOfSizeType == 2
#define cH_FIFO_byte_GetPacketSize(_Size,_Buffer)                 (_Size)=((H_FIFO_SizeType)(_Buffer)[0])|(((H_FIFO_SizeType)(_Buffer)[1])<<8)
#define cH_FIFO_byte_SetPacketSize(_Buffer,_Size)                 do{\
                                                                    (_Buffer)[0]=(H_FIFO_byte_Type)(_Size);\
                                                                    (_Buffer)[1]=(H_FIFO_byte_Type)((_Size)>>8);\
                                                                  }while(0)
#elif H_FIFO_SizeOfSizeType == 4
#define cH_FIFO_byte_GetPacketSize(_Size,_Buffer)                 (_Size)=((H_FIFO_SizeType)(_Buffer)[0])|(((H_FIFO_SizeType)(_Buffer)[1])<<8)|(((H_FIFO_SizeType)(_Buffer)[2])<<16)|(((H_FIFO_SizeType)(_Buffer)[3])<<24)
#define cH_FIFO_byte_SetPacketSize(_Buffer,_Size)                 do{\
                                                                    (_Buffer)[0]=(H_FIFO_byte_Type)(_Size);\
                                                                    (_Buffer)[1]=(H_FIFO_byte_Type)((_Size)>>8);\
                                                                    (_Buffer)[2]=(H_FIFO_byte_Type)((_Size)>>16);\
                                                                    (_Buffer)[3]=(H_FIFO_byte_Type)((_Size)>>24);\
                                                                  }while(0)
#elif H_FIFO_SizeOfSizeType == 8
#define cH_FIFO_byte_GetPacketSize(_Size,_Buffer)                 (_Size)=((H_FIFO_SizeType)(_Buffer)[0])|(((H_FIFO_SizeType)(_Buffer)[1])<<8)|(((H_FIFO_SizeType)(_Buffer)[2])<<16)|(((H_FIFO_SizeType)(_Buffer)[3])<<24)|(((H_FIFO_SizeType)(_Buffer)[4])<<32)|(((H_FIFO_SizeType)(_Buffer)[5])<<40)|(((H_FIFO_SizeType)(_Buffer)[6])<<48)|(((H_FIFO_SizeType)(_Buffer)[7])<<56)
#define cH_FIFO_byte_SetPacketSize(_Buffer,_Size)                 do{\
                                                                    (_Buffer)[0]=(H_FIFO_byte_Type)(_Size);\
                                                                    (_Buffer)[1]=(H_FIFO_byte_Type)((_Size)>>8);\
                                                                    (_Buffer)[2]=(H_FIFO_byte_Type)((_Size)>>16);\
                                                                    (_Buffer)[3]=(H_FIFO_byte_Type)((_Size)>>24);\
                                                                    (_Buffer)[4]=(H_FIFO_byte_Type)((_Size)>>32);\
                                                                    (_Buffer)[5]=(H_FIFO_byte_Type)((_Size)>>40);\
                                                                    (_Buffer)[6]=(H_FIFO_byte_Type)((_Size)>>48);\
                                                                    (_Buffer)[7]=(H_FIFO_byte_Type)((_Size)>>56);\
                                                                  }while(0)
#else
#error "请选择可用的位宽"
#endif




H_FIFO_SizeType H_FIFO_byte_ReadSize(volatile void* Buffer,H_FIFO_SizeType Id){
  volatile H_FIFO_byte_Type* dst;
  H_FIFO_SizeType r;

  dst=(volatile H_FIFO_byte_Type*)Buffer;
  dst=&dst[Id];
  
  cH_FIFO_byte_GetPacketSize(r,dst);

  return r;
}

void H_FIFO_byte_WriteSize(volatile void* Buffer,H_FIFO_SizeType Id,H_FIFO_SizeType Size){
  volatile H_FIFO_byte_Type* dst;

  dst=(volatile H_FIFO_byte_Type*)Buffer;
  dst=&dst[Id];
  
  cH_FIFO_byte_SetPacketSize(dst,Size);
}

void H_FIFO_byte_Copy(volatile void* Buffer,H_FIFO_SizeType Id,const volatile void* Src,H_FIFO_SizeType Size){
  volatile H_FIFO_byte_Type* dst;
  const H_FIFO_byte_Type* src;
  H_FIFO_SizeType size;

  dst=(volatile H_FIFO_byte_Type*)Buffer;
  dst=&dst[Id];
  src=(const H_FIFO_byte_Type*)Src;
  size=Size;
  while(size>7){
    dst[0]=src[0];
    dst[1]=src[1];
    dst[2]=src[2];
    dst[3]=src[3];
    dst[4]=src[4];
    dst[5]=src[5];
    dst[6]=src[6];
    dst[7]=src[7];

    size-=8;
    dst=&dst[8];
    src=&src[8];
  }
  for(H_FIFO_SizeType i=0;i<size;i++){
    dst[i]=src[i];
  }

}

const void* H_FIFO_byte_GetPointer(volatile void* Buffer,H_FIFO_SizeType Id){
  volatile H_FIFO_byte_Type* r;

  r=(volatile H_FIFO_byte_Type*)Buffer;
  r=&r[Id];

  return (const void*)r;
}



